<?php

// +----------------------------------------------------------------------
// | TAODUDU.COM  [ Simple Efficient Excellent ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016 http://www.taodudu.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: ubten <462193409@qq.com> http://www.ubten.com/
// +----------------------------------------------------------------------
namespace Home\Controller;
use Home\Controller\BaseController;

class SeckillController extends BaseController {
    
    public function _initialize(){
         parent::_initialize();
    }
    
    public function index(){
        $where['seckill_start_time'] = array('GT',NOW_TIME);
        $where['seckill_state'] = 1;
        $where['seckil_type'] = 1;
        $arrss = M('seckill')->where($where)->select();
        foreach ($arrss as $key => $value) {
            $map['goods_id'] = $value['seckill_goods_id'];
            $arrss[$key]['goods'] = M('goods')->field('goods_title,goods_thumb,goods_markprice')->where($map)->find();
        }
        $this->assign('arrss', $arrss);
        
        $where['seckill_start_time'] = array('elt',NOW_TIME);
        $where['seckill_end_time'] = array('egt',NOW_TIME);
        $where['seckill_state'] = 1;
        $where['seckil_type'] = 1;
        $arr = M('seckill')->where($where)->select();
        foreach ($arr as $key => $value) {
            $map['goods_id'] = $value['seckill_goods_id'];
            $arr[$key]['goods'] = M('goods')->field('goods_title,goods_thumb,goods_markprice')->where($map)->find();
        }
        $this->assign('arr', $arr);
        
        $wheres['seckill_end_time'] = array('elt',NOW_TIME);
        $wheres['seckil_type'] = 1;
        $arrs = M('seckill')->where($wheres)->select();
        
        foreach ($arrs as $key => $value) {
            $map['goods_id'] = $value['seckill_goods_id'];
            $arrs[$key]['goods'] = M('goods')->field('goods_title,goods_thumb,goods_markprice')->where($map)->find();
        }
        $this->assign('arrs', $arrs);
        
        $this->display();
    }

    
    
    public function discount(){
        $where['seckill_end_time'] = array('egt',NOW_TIME);
        $where['seckill_state'] = 1;
        $where['seckil_type'] = 2;
        $arr = M('seckill')->where($where)->select();
        foreach ($arr as $key => $value) {
            $map['goods_id'] = $value['seckill_goods_id'];
            $arr[$key]['goods'] = M('goods')->field('goods_title,goods_thumb,goods_markprice')->where($map)->find();
        }
        $this->assign('arr', $arr);
        $this->display();
    }
    
    
    public function msDetails(){
        $id = I('id');
        $map['seckill_id'] = $id;
        $re = M('seckill')->where($map)->find();
        $maps['goods_id'] = $re['seckill_goods_id'];
        $goods = M('goods')->where($maps)->find();
        $goods['images'] = unserialize($goods['goods_images']);
        
        $userID = session('user_id');
        if(empty($userID)){
            $userID =0;
        }
        
        //商家信息
        $storeWhere['store_id'] = $goods['store_id'];
        $store = M('store')->where($storeWhere)->find();
        $this->assign('store', $store);
        
        $this->assign('userID', $userID);
        $this->assign('goods', $goods);
        $this->assign('re', $re);
        $this->display();
    }
    
    
    
}
